﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
using FSS.BLL.Entities;
using FSS.BLL.Services;
using FSS.BLL;

namespace SalesManagement.Controls.List
{
    public partial class InOutMethodForm : System.Web.UI.UserControl
    {
        public event EventHandler SaveClick;
        private void OnSaveClick()
        {
            if (SaveClick != null)
            {
                SaveClick(this, EventArgs.Empty);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        public void Show()
        {
            this.winDetails.Show();
        }
        public void Show(string inoutmethodId)
        {
            InOutMethodEntity inoutMethodE = new InOutMethodEntity();
            InOutMethodService inoutMethodS = InOutMethodService.GetInstance();
            inoutMethodE.MethodId = int.Parse(inoutmethodId);
            inoutMethodE = inoutMethodS.LoadByPrimaryKey(inoutMethodE);
            if (null == inoutMethodE)
                return;
            hdfInOutMethodId.Value = inoutMethodE.MethodId;
            txtInOutMethodName.Text = inoutMethodE.MethodName;
            txtDescription.Text = inoutMethodE.Description;
            ckbIsActive.Checked = inoutMethodE.IsActive;
            this.winDetails.Show();
        }
        public void ShowAndReset()
        {
            this.FormPanel1.Reset();
            this.winDetails.Show();
        }
        protected void btnSave_Click(object sender, DirectEventArgs e)
        {
            InOutMethodEntity inoutMethodE = new InOutMethodEntity();
            InOutMethodService inoutMethodS = InOutMethodService.GetInstance();
            if ("" != hdfInOutMethodId.Value.ToString())
            {
                string inoutMethodId = hdfInOutMethodId.Value.ToString();
                inoutMethodE.MethodId = int.Parse(inoutMethodId);
                inoutMethodE = inoutMethodS.LoadByPrimaryKey(inoutMethodE);
                inoutMethodE.MethodName = txtInOutMethodName.Text;
                inoutMethodE.Description = txtDescription.Text;
                inoutMethodE.IsActive = ckbIsActive.Checked;
                inoutMethodE.UpdatedDate = DateTime.Now;
                inoutMethodE.UpdatedBy = FSSContext.Current.User.EmployeeId;
                inoutMethodS.Update(inoutMethodE);
            }
            else
            {
                inoutMethodE.MethodName = txtInOutMethodName.Text;
                inoutMethodE.Description = txtDescription.Text;
                inoutMethodE.IsActive = ckbIsActive.Checked;
                inoutMethodE.CreatedDate = DateTime.Now;
                inoutMethodE.CreatedBy = FSSContext.Current.User.EmployeeId;
                inoutMethodE.UpdatedDate = DateTime.Now;
                inoutMethodE.UpdatedBy = FSSContext.Current.User.EmployeeId;
                inoutMethodS.Insert(inoutMethodE);
            }
            this.winDetails.Hide();
            OnSaveClick();
        }
    }
}